<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="选手名字" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入选手名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国籍" prop="country">
        <el-input
          v-model="queryParams.country"
          placeholder="请输入国籍"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在赛区" prop="locatedArea">
<!--        <el-input-->
<!--          v-model="queryParams.locatedArea"-->
<!--          placeholder="请输入所在赛区"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
        <el-select
          v-model="queryParams.locatedArea"
          placeholder="请选择比赛赛区" clearable>
          <el-option
            v-for="item in locatedAreaList1"
            :value="item.value"
            :label="item.label"
            :key="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="比赛场地" prop="competitionVenue">
        <el-select
          v-model="queryParams.competitionVenue"
          placeholder="请选择比赛场地" clearable>
          <el-option
            v-for="item in competitionVenueList1"
            :value="item.value"
            :label="item.label"
            :key="item.value"
          />
        </el-select >
      </el-form-item>
      <el-form-item label="参与项目名称" prop="pationProjectName" >
        <el-select v-model="queryParams.pationProjectName" placeholder="请选择参与项目名称" clearable>
          <el-option
            v-for="dict in optionList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="个人名次" prop="individualRanking">
        <!--          <el-input v-model="form.individualRanking" placeholder="请输入个人名次" />-->
        <el-select v-model="queryParams.individualRanking" placeholder="请选择参与项目名称">
          <el-option
            v-for="dict in individualRankingList1"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:table:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:table:remove']"
        >批量删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table  border v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="选手名字" align="center" prop="name" />
      <el-table-column label="国籍" align="center" prop="country" />
      <el-table-column label="所在赛区" align="center" prop="locatedArea" >
        <template slot-scope="scope">
          {{scope.row.locatedArea == '1' ? '北京赛区':scope.row.locatedArea == '2' ? '北京延庆赛区':scope.row.locatedArea == '3' ? '张家口赛区':'--'  }}
        </template>
      </el-table-column>
      <el-table-column label="比赛场地" align="center" prop="competitionVenue" :formatter="formatterCompetitionVenue" />
      <el-table-column label="参与项目名称" align="center" prop="pationProjectName" :formatter="projectNameFormatter"/>
      <el-table-column label="项目种类" align="center" prop="pationProjectType" >
        <template slot-scope="scope">
          {{scope.row.pationProjectType == 1 ? '单人赛':scope.row.pationProjectType == 2 ? '双人赛':scope.row.pationProjectType == 3 ?'团体赛':'--' }}
        </template>
      </el-table-column>
      <el-table-column label="得分" align="center" prop="score" />
      <el-table-column label="个人名次" align="center" prop="individualRanking" />
      <el-table-column label="奖牌" align="center" prop="ranking" >
        <template slot-scope="scope">
          <div v-if="scope.row.individualRanking == 2">
            <img style="width: 30px;height: 44px" src="https://inews.gtimg.com/newsapp_bt/0/1231113333499_5413/0">
          </div>
          <div v-if="scope.row.individualRanking == 1">
            <img style="width: 30px;height: 44px" src="https://inews.gtimg.com/newsapp_bt/0/1231112549302_5173/0">
          </div>
          <div v-if="scope.row.individualRanking == 3">
            <img style="width: 30px;height: 44px" src="https://inews.gtimg.com/newsapp_bt/0/1231113331290_3204/0">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:table:edit']"
          >修改</el-button>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:table:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改选手成绩录入对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="选手名字" prop="name">
<!--          {{form.name}}-->
          <el-select v-model="form.name" placeholder="请选择选手名字" @change="onclick(form.name)" clearable>
            <el-option
              v-for="dict in palerList"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
<!--          <el-input style="width: 220px" v-model="form.name" placeholder="请输入选手名字" />-->
        </el-form-item>
        <el-form-item label="国籍" prop="country">
          <el-input style="width: 220px" v-model="form.country" placeholder="请输入国籍" />
        </el-form-item>
        <el-form-item label="所在赛区" prop="locatedArea">
          <el-select v-model="form.locatedArea" placeholder="请选择所在赛区" clearable>
            <el-option
              v-for="dict in locatedAreaList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="比赛场地" prop="competitionVenue">
<!--          <el-input v-model="form.competitionVenue" placeholder="请输入比赛场地" />-->
          <el-select v-model="form.competitionVenue" placeholder="请选择比赛场地" clearable>
            <el-option
              v-for="dict in competitionVenueList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="参与项目名称" prop="pationProjectName">
          <el-select v-model="form.pationProjectName" placeholder="请选择参与项目名称" clearable>
            <el-option
              v-for="dict in options"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="参与项目种类" prop="pationProjectType">
          <el-select v-model="form.pationProjectType" placeholder="请选择项目种类" clearable>
            <el-option
              v-for="dict in projectTypeList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="得分" prop="score" width="220px">
          <el-input style="width: 220px" v-model="form.score" placeholder="请输入得分" />
        </el-form-item>
        <el-form-item label="个人名次" prop="individualRanking">
<!--          <el-input v-model="form.individualRanking" placeholder="请输入个人名次" />-->
          <el-select v-model="form.individualRanking" placeholder="请选择参与项目名称" clearable>
            <el-option
              v-for="dict in individualRankingList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTable, getTable, delTable, addTable, updateTable } from "@/api/system/table";
import { palerPInformation} from "@/api/system/pInformation";


export default {
  name: "Table",
  dicts: ['sys_job_group'],
  data() {
    return {
      //所在场地 查询条件
      competitionVenueList1:[
        {
          value: '1',
          label: '首都体育馆'
        },
        {
          value: '2',
          label: '国家速滑馆'
        },
        {
          value: '3',
          label: '国家体育馆'
        },
        {
          value: '4',
          label: '五棵松体育中心'
        },
        {
          value: '5',
          label: '国家游泳中心'
        },
        {
          value: '6',
          label: '首钢滑雪大跳台中心'
        },
        {
          value: '7',
          label: '国家雪车雪橇中心'
        },
        {
          value: '8',
          label: '国家高山滑雪中心'
        },
        {
          value: '9',
          label: '云顶滑雪公园'
        },
        {
          value: '10',
          label: '国家跳台滑雪中心'
        },
        {
          value: '11',
          label: '国家越野滑雪中心'
        },
        {
          value: '12',
          label: '国家冬季两项中心'
        }
      ],
      //所在赛区 查询条件
      locatedAreaList1:[
        {
          value: '1',
          label:'北京赛区'
        },
        {
          value: '2',
          label:'北京延庆赛区'
        },
        {
          value: '3',
          label:'张家口赛区'
        }
      ],
      //所在赛区
      locatedAreaList:[
        {
          value: '1',
          label:'北京赛区'
        },
        {
          value: '2',
          label:'北京延庆赛区'
        },
        {
          value: '3',
          label:'张家口赛区'
        }
      ],
      optionList:[
        {
          value: '1',
          label: '短道速滑'
        }, {
          value: '2',
          label: '速度滑冰'
        }, {
          value: '3',
          label: '花样滑冰'
        }, {
          value: '4',
          label: '冰球'
        }, {
          value: '5',
          label: '冰壶'
        }, {
          value: '6',
          label: '雪车'
        }, {
          value: '7',
          label: '钢架雪车'
        }, {
          value: '8',
          label: '雪橇'
        }, {
          value: '9',
          label: '冬季两项'
        }, {
          value: '10',
          label: '高山滑雪'
        }, {
          value: '11',
          label: '自由式滑雪'
        }, {
          value: '12',
          label: '单板滑雪'
        }, {
          value: '13',
          label: '越野滑雪'
        }, {
          value: '14',
          label: '跳台滑雪'
        },{
          value: '15',
          label: '北欧两项'
        }
      ],
      //比赛项目
      options:[
        {
          value: '1',
          label: '短道速滑'
        }, {
          value: '2',
          label: '速度滑冰'
        }, {
          value: '3',
          label: '花样滑冰'
        }, {
          value: '4',
          label: '冰球'
        }, {
          value: '5',
          label: '冰壶'
        }, {
          value: '6',
          label: '雪车'
        }, {
          value: '7',
          label: '钢架雪车'
        }, {
          value: '8',
          label: '雪橇'
        }, {
          value: '9',
          label: '冬季两项'
        }, {
          value: '10',
          label: '高山滑雪'
        }, {
          value: '11',
          label: '自由式滑雪'
        }, {
          value: '12',
          label: '单板滑雪'
        }, {
          value: '13',
          label: '越野滑雪'
        }, {
          value: '14',
          label: '跳台滑雪'
        },{
          value: '15',
          label: '北欧两项'
        }
      ],
      //比赛场地
      competitionVenueList:[
        {
          value: '1',
          label: '首都体育馆'
        },
        {
          value: '2',
          label: '国家速滑馆'
        },
        {
          value: '3',
          label: '国家体育馆'
        },
        {
          value: '4',
          label: '五棵松体育中心'
        },
        {
          value: '5',
          label: '国家游泳中心'
        },
        {
          value: '6',
          label: '首钢滑雪大跳台中心'
        },
        {
          value: '7',
          label: '国家雪车雪橇中心'
        },
        {
          value: '8',
          label: '国家高山滑雪中心'
        },
        {
          value: '9',
          label: '云顶滑雪公园'
        },
        {
          value: '10',
          label: '国家跳台滑雪中心'
        },
        {
          value: '11',
          label: '国家越野滑雪中心'
        },
        {
          value: '12',
          label: '国家冬季两项中心'
        }
      ],
      individualRankingList1:[
        {
          value: 1,
          label: '第一名'
        }, {
          value: 2,
          label: '第二名'
        }, {
          value: 3,
          label: '第三名'
        },
      ],
      //名次
      individualRankingList:[
        {
          value: 1,
          label: '第一名'
        }, {
          value: 2,
          label: '第二名'
        }, {
          value: 3,
          label: '第三名'
        },
      ],
      //项目种类
      projectTypeList:[
        {
          value: 1,
          label: '单人赛'
        },
        {
          value: 2,
          label: '双人赛'
        },
        {
          value: 3,
          label: '团体赛'
        }
      ],
      palerList:[],
      countryList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 选手成绩录入表格数据
      tableList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        country: null,
        locatedArea: null,
        competitionVenue: null,
        pationProjectName: null,
        individualRanking:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getPlayerList()
  },
  methods: {
    //比赛场地
    formatterCompetitionVenue(row,cloumn){
      switch(row.competitionVenue){
        case '1':
          return '首都体育馆';
          break;
        case '2':
          return '国家速滑馆';
          break;
        case '3':
          return '国家体育馆';
          break;
        case '4':
          return '五棵松体育中心';
          break;
        case '5':
          return '国家游泳中心';
          break;
        case '6':
          return '首钢滑雪大跳台中心';
          break;
        case '7':
          return '国家雪车雪橇中心';
          break;
        case '8':
          return '国家高山滑雪中心';
          break;
        case '9':
          return '云顶滑雪公园';
          break;
        case '10':
          return '国家跳台滑雪中心';
          break;
        case '11':
          return '国家越野滑雪中心';
          break;
        case '12':
          return '国家冬季两项中心';
          break;
        default:
          return '未知';
      }
    },
    //项目名称
    projectNameFormatter(row,cloumn){
      switch(row.pationProjectName){
        case '1':
          return '短道速滑';
          break;
        case '2':
          return '速度滑冰';
          break;
        case '3':
          return '花样滑冰';
          break;
        case '4':
          return '冰球';
          break;
        case '5':
          return '冰壶';
          break;
        case '6':
          return '雪车';
          break;
        case '7':
          return '钢架雪车';
          break;
        case '8':
          return '雪橇';
          break;
        case '9':
          return '冬季两项';
          break;
        case '10':
          return '高山滑雪';
          break;
        case '11':
          return '自由式滑雪';
          break;
        case '12':
          return '单板滑雪';
          break;
        case '13':
          return '跳台滑雪';
          break;
        case '14':
          return '越野滑雪';
          break;
        case '15':
          return '北欧两项';
          break;
        default:
          return '未知';
      }
    },
    onclick(id){
      const self = this
      debugger
      for (let i =0 ;i<self.palerList.length;i++){
        if(self.palerList[i].id == id){
          // debugger
          self.form.name = self.palerList[i].name
          self.form.createUsername = self.palerList[i].createUsername
          self.form.pationProjectType = self.palerList[i].projectType
          self.form.pationProjectName = self.palerList[i].projectName
          self.form.competitionVenue = self.palerList[i].competitionVenue
          self.form.locatedArea = self.palerList[i].locatedArea
          self.form.country = self.palerList[i].country
        }
      }
    },
    /**
     * 查询选手列表下拉框
     */
    getPlayerList(){
      this.loading = true;
      palerPInformation(this.queryParams).then(response => {
        this.palerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 查询选手成绩录入列表 */
    getList() {
      this.loading = true;
      this.queryParams.createUsername = this.$store.state.user.name,
      listTable(this.queryParams).then(response => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        country: null,
        locatedArea: null,
        competitionVenue: null,
        tournamentProgress: null,
        score: null,
        individualRanking: null,
        pationProjectName: null,
        isDeleted: null,
        createUserid: null,
        createUsername: null,
        createTime: null,
        serverIp: null,
        updateUserid: null,
        updateUsername: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加选手成绩录入";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTable(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改选手成绩录入";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTable(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTable(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除选手成绩录入编号为"' + ids + '"的数据项？').then(function() {
        return delTable(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/table/export', {
        ...this.queryParams
      }, `table_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
